package com.maben.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * 首页控制类
 */
@RestController
@Slf4j
@RequestMapping("home")
public class HomeController {
    /**
     * 跳转到首页
     */
    @ApiOperation("跳转到首页")
    @GetMapping("")
    public ModelAndView home() {
        final ModelAndView modelAndView = new ModelAndView("home");
        modelAndView.addObject("loginId", StpUtil.getLoginId());
        modelAndView.addObject("token", StpUtil.getTokenValue());
        modelAndView.addObject("tokenInfo", StpUtil.getTokenInfo());
        return modelAndView;
    }

    /**
     * 测试登录成功后，获取信息
     */
    @ApiOperation("test001")
    @GetMapping("test001")
    public SaResult test001() {
        return SaResult.data(StpUtil.getTokenValue());
    }
}
